<!-- ------------------------------------------------------------------------- -->
<!-- ------------------------------------------------------------------------- -->
<!-- ---------------------- 流调管理--密接人员管理 ---------------------------- -->
<!-- ------------------------------------------------------------------------- -->
<!-- ------------------------------编辑的tag---------------------------------- -->
<!-- -------------------------编辑的tag--流行病学轨迹调查----------------------------- -->

<template>
  <div class="box">
    <div class="form-box">
      <el-form
        ref="ruleFormRef"
        :model="ruleForm"
        :rules="rules"
        label-width="120px"
        class="demo-ruleForm"
        :size="formSize"
        status-icon
      >
        <el-button type="primary" @click="addForm = true">新增</el-button>

        <!-- 新增模态框 -->
        <el-dialog v-model="addForm" title="新增流行病学轨迹">
          <el-form :model="form" style="padding-top: 30px;width:100%;">
            <el-form-item label="时间:" :label-width="formLabelWidth">
              <div class="demo-date-picker">
                <div class="block">
                  <el-date-picker
                    v-model="addDate"
                    type="date"
                    placeholder="请选择"
                    :disabled-date="disabledDate"
                    :size="size"
                    style="width: 300px"
                  />
                </div>
              </div>
            </el-form-item>

            <el-form-item
              label="地点:"
              :label-width="formLabelWidth"
              size="large"
            >
              <el-input
                v-model="form.name"
                autocomplete="off"
                style="width: 90%"
              />
            </el-form-item>
            <!-- img -->
            <el-form-item
              label="接触人:"
              :label-width="formLabelWidth"
              size="large"
            >
              <el-input
                v-model="form.name"
                autocomplete="off"
                style="width: 90%"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item
              label="活动:"
              :label-width="formLabelWidth"
              size="large"
            >
              <el-input
                v-model="form.name"
                autocomplete="off"
                style="width: 90%"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item
              label="交通工具:"
              :label-width="formLabelWidth"
              size="large"
            >
              <el-input
                v-model="form.name"
                autocomplete="off"
                style="width: 90%"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item
              label="个人防护情况:"
              :label-width="formLabelWidth"
              size="large"
            >
              <el-input
                v-model="form.name"
                autocomplete="off"
                style="width: 90%"
                placeholder="请输入"
              />
            </el-form-item>
            <el-form-item
              label="对方防护情况:"
              :label-width="formLabelWidth"
              size="large"
            >
              <el-input
                v-model="form.name"
                autocomplete="off"
                style="width: 90%"
                placeholder="请输入"
              />
            </el-form-item>
          </el-form>
          <template #footer>
            <span class="dialog-footer">
              <el-button @click="addForm = false">取消</el-button>
              <el-button type="primary" @click="addForm = false">
                确定
              </el-button>
            </span>
          </template>
        </el-dialog>

        <el-timeline class="table">
          <el-timeline-item timestamp="2018/4/12" placement="top">
            <div class="btn-box">
              <el-button
                type="primary"
                :icon="Edit"
                circle
                size="small"
                @click="editForm = true"
              />
              <!-- 编辑模态框 -->
              <el-dialog v-model="editForm" title="编辑流行病学轨迹">
                <el-form :model="eForm" style="padding-top: 30px;width: 100%;">
                  <el-form-item label="时间:" :label-width="formLabelWidth">
                    <div class="demo-date-picker">
                      <div class="block">
                        <el-date-picker
                          v-model="editForm"
                          type="date"
                          placeholder="请选择"
                          :disabled-date="disabledDate"
                          :size="size"
                          style="width: 300px"
                        />
                      </div>
                    </div>
                  </el-form-item>

                  <el-form-item
                    label="地点:"
                    :label-width="formLabelWidth"
                    size="large"
                  >
                    <el-input
                      v-model="eForm.name"
                      autocomplete="off"
                      style="width: 90%"
                    />
                  </el-form-item>
                  <!-- img -->
                  <el-form-item
                    label="接触人:"
                    :label-width="formLabelWidth"
                    size="large"
                  >
                    <el-input
                      v-model="eForm.name"
                      autocomplete="off"
                      style="width: 90%"
                      placeholder="请输入"
                    />
                  </el-form-item>
                  <el-form-item
                    label="活动:"
                    :label-width="formLabelWidth"
                    size="large"
                  >
                    <el-input
                      v-model="eForm.name"
                      autocomplete="off"
                      style="width: 90%"
                      placeholder="请输入"
                    />
                  </el-form-item>
                  <el-form-item
                    label="交通工具:"
                    :label-width="formLabelWidth"
                    size="large"
                  >
                    <el-input
                      v-model="eForm.name"
                      autocomplete="off"
                      style="width: 90%"
                      placeholder="请输入"
                    />
                  </el-form-item>
                  <el-form-item
                    label="个人防护情况:"
                    :label-width="formLabelWidth"
                    size="large"
                  >
                    <el-input
                      v-model="eForm.name"
                      autocomplete="off"
                      style="width: 90%"
                      placeholder="请输入"
                    />
                  </el-form-item>
                  <el-form-item
                    label="对方防护情况:"
                    :label-width="formLabelWidth"
                    size="large"
                  >
                    <el-input
                      v-model="eForm.name"
                      autocomplete="off"
                      style="width: 90%"
                      placeholder="请输入"
                    />
                  </el-form-item>
                </el-form>
                <template #footer>
                  <span class="dialog-footer">
                    <el-button @click="editForm = false">取消</el-button>
                    <el-button type="primary" @click="editForm = false">
                      确定
                    </el-button>
                  </span>
                </template>
              </el-dialog>

              <el-button style="margin-left:12px;" type="danger" :icon="Delete" circle size="small" @click="deleteForm" />
            </div>

            <el-row>
              <el-col :span="6" class="title"
                ><div class="grid-content ep-bg-purple" />
                <p>地点:</p>
              </el-col>
              <el-col :span="18" class="banner"
                ><div class="grid-content ep-bg-purple-light" />
                <p>苏州市山塘街星巴克咖啡馆</p>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6" class="title"
                ><div class="grid-content ep-bg-purple" />
                <p>地点:</p>
              </el-col>
              <el-col :span="18" class="banner"
                ><div class="grid-content ep-bg-purple-light" />
                <p>苏州市山塘街星巴克咖啡馆</p>
              </el-col> </el-row
            ><el-row>
              <el-col :span="6" class="title"
                ><div class="grid-content ep-bg-purple" />
                <p>地点:</p>
              </el-col>
              <el-col :span="18" class="banner"
                ><div class="grid-content ep-bg-purple-light" />
                <p>苏州市山塘街星巴克咖啡馆</p>
              </el-col> </el-row
            ><el-row>
              <el-col :span="6" class="title"
                ><div class="grid-content ep-bg-purple" />
                <p>地点:</p>
              </el-col>
              <el-col :span="18" class="banner"
                ><div class="grid-content ep-bg-purple-light" />
                <p>苏州市山塘街星巴克咖啡馆</p>
              </el-col> </el-row
            ><el-row>
              <el-col :span="6" class="title"
                ><div class="grid-content ep-bg-purple" />
                <p>地点:</p>
              </el-col>
              <el-col :span="18" class="banner"
                ><div class="grid-content ep-bg-purple-light" />
                <p>苏州市山塘街星巴克咖啡馆</p>
              </el-col> </el-row
            ><el-row>
              <el-col :span="6" class="title"
                ><div class="grid-content ep-bg-purple" />
                <p>地点:</p>
              </el-col>
              <el-col :span="18" class="banner"
                ><div class="grid-content ep-bg-purple-light" />
                <p>苏州市山塘街星巴克咖啡馆</p>
              </el-col>
            </el-row>
          </el-timeline-item>

          <el-timeline-item timestamp="2018/4/12" placement="top">
            <div class="btn-box">
              <el-button type="primary" :icon="Edit" circle size="small" @click="editForm = true" />
              <el-button type="danger" :icon="Delete" circle size="small" @click="deleteForm" />
            </div>
            <el-row>
              <el-col :span="6" class="title"
                ><div class="grid-content ep-bg-purple" />
                <p>地点:</p>
              </el-col>
              <el-col :span="18" class="banner"
                ><div class="grid-content ep-bg-purple-light" />
                <p>苏州市山塘街星巴克咖啡馆</p>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6" class="title"
                ><div class="grid-content ep-bg-purple" />
                <p>地点:</p>
              </el-col>
              <el-col :span="18" class="banner"
                ><div class="grid-content ep-bg-purple-light" />
                <p>苏州市山塘街星巴克咖啡馆</p>
              </el-col> </el-row
            ><el-row>
              <el-col :span="6" class="title"
                ><div class="grid-content ep-bg-purple" />
                <p>地点:</p>
              </el-col>
              <el-col :span="18" class="banner"
                ><div class="grid-content ep-bg-purple-light" />
                <p>苏州市山塘街星巴克咖啡馆</p>
              </el-col> </el-row
            ><el-row>
              <el-col :span="6" class="title"
                ><div class="grid-content ep-bg-purple" />
                <p>地点:</p>
              </el-col>
              <el-col :span="18" class="banner"
                ><div class="grid-content ep-bg-purple-light" />
                <p>苏州市山塘街星巴克咖啡馆</p>
              </el-col> </el-row
            ><el-row>
              <el-col :span="6" class="title"
                ><div class="grid-content ep-bg-purple" />
                <p>地点:</p>
              </el-col>
              <el-col :span="18" class="banner"
                ><div class="grid-content ep-bg-purple-light" />
                <p>苏州市山塘街星巴克咖啡馆</p>
              </el-col> </el-row
            ><el-row>
              <el-col :span="6" class="title"
                ><div class="grid-content ep-bg-purple" />
                <p>地点:</p>
              </el-col>
              <el-col :span="18" class="banner"
                ><div class="grid-content ep-bg-purple-light" />
                <p>苏州市山塘街星巴克咖啡馆</p>
              </el-col>
            </el-row>
          </el-timeline-item>
        </el-timeline>

        <el-form-item style="padding-top: 100px">
          <el-button @click="resetForm(ruleFormRef)">取消</el-button>
          <el-button type="primary" @click="submitForm(ruleFormRef)">
            确定
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, onBeforeMount, reactive, ref } from "vue";
import type { FormInstance, FormRules } from "element-plus";
import { ElMessage, ElMessageBox } from 'element-plus'
import { Delete, Edit } from "@element-plus/icons-vue";
import { useRoute,useRouter } from "vue-router";
import  axios  from "@/util/http";
export default defineComponent({
  name: "TightTrack",
  setup() {
    const route = useRoute()
    const router = useRouter()
    const formSize = ref("large");
    const ruleFormRef = ref<FormInstance>();
    const value1 = ref("");
    const addDate = ref(""); //登记日期选择
    const size = ref<"default" | "large" | "small">("large"); //新增---时间
    // 新增
    const dialogTableVisible = ref(false);
    const addForm = ref(false);
    const formLabelWidth = "140px";
    //编辑
    const editForm = ref(false);
    // 删除
      // 删除
      const deleteForm = () => {
  ElMessageBox.confirm(
    '删除后将不可恢复,是否继续此操作?',
    '删除确认',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      ElMessage({
        type: 'success',
        message: '删除成功',
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '删除失败',
      })
    })
}

  onBeforeMount(()=>{
      let id = route.query.rowId
      console.log(id);
      axios({
        method:'get',
        url:'cryptographer/finddiseaseSurvey',
        params:{id:id}
      }).then(res=>{
        console.log(res,'数据');
        console.log(res.data.data);
        
      })
    })


    const form = reactive({
      name: "",
      region: "",
      date1: "",
      date2: "",
      delivery: false,
      type: [],
      resource: "",
      desc: "",
    });

    const eForm = reactive({
      name: "",
      region: "",
      date1: "",
      date2: "",
      delivery: false,
      type: [],
      resource: "",
      desc: "",
    });
    //登记日期禁用函数
    const disabledDate = (time: Date) => {
      return time.getTime() > Date.now();
    };

    const ruleForm = reactive({
      name: "Hello",
      region: "",
      count: "",
      date1: "",
      date2: "",
      delivery: false,
      type: [],
      resource: "",
      desc: "",
    });

    const rules = reactive<FormRules>({
      name: [
        {
          required: true,
          message: "Please input Activity name",
          trigger: "blur",
        },
        { min: 3, max: 5, message: "Length should be 3 to 5", trigger: "blur" },
      ],
      region: [
        {
          required: true,
          message: "Please select Activity zone",
          trigger: "change",
        },
      ],
      count: [
        {
          required: false,
          message: "Please select Activity count",
          trigger: "change",
        },
      ],
      date1: [
        {
          type: "date",
          required: true,
          message: "Please pick a date",
          trigger: "change",
        },
      ],
      date2: [
        {
          type: "date",
          required: true,
          message: "Please pick a time",
          trigger: "change",
        },
      ],
      type: [
        {
          type: "array",
          required: true,
          message: "Please select at least one activity type",
          trigger: "change",
        },
      ],
      resource: [
        {
          required: true,
          message: "Please select activity resource",
          trigger: "change",
        },
      ],
      desc: [
        {
          required: true,
          message: "Please input activity form",
          trigger: "blur",
        },
      ],
    });

    const submitForm = async (formEl: FormInstance | undefined) => {
      if (!formEl) return;
      await formEl.validate((valid, fields) => {
        if (valid) {
          console.log("submit!");
        } else {
          console.log("error submit!", fields);
        }
      });
    };

    const resetForm = (formEl: FormInstance | undefined) => {
      if (!formEl) return;
      formEl.resetFields();
    };

    const options = Array.from({ length: 10000 }).map((_, idx) => ({
      value: `${idx + 1}`,
      label: `${idx + 1}`,
    }));

    return {
      formSize,
      ruleFormRef,
      ruleForm,
      rules,
      submitForm,
      resetForm,
      options,
      value1,
      Edit,
      Delete,
      addDate,
      size,
      dialogTableVisible,
      addForm,
      formLabelWidth,
      disabledDate,
      form,editForm,eForm,deleteForm
    };
  },
});
</script>

<style scoped lang="less">
.box {
  width: 100%;
  background-color: #fff;
}
.el-form {
  width: 50%;
  background-color: #fff;
  padding-top: 100px;
}
.el-timeline {
  margin-top: 30px;
}
.table {
  .el-col {
    border: 0.5px solid rgba(0, 0, 0, 0.04);
    height: 50px;
    display: flex;
    align-items: center;
  }
}

.title {
  background-color: #f9f9f9;
  display: flex;
  justify-content: flex-end;
  padding-right: 10px;
}
.banner {
  display: flex;
  padding-left: 10px;
}
.form-box {
  width: 90%;
}

.btn-box {
  height: 30px;
}
</style>
